package com.recyclebanner;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hxkcloud.nurse.R;


/**
 * 和banner配套使用的小点
 * */
public class ImageCountView extends LinearLayout {
	private ImageView[] images;
	private int round_select =R.drawable.select_icon;//select_icon
	private int round_unselect = R.drawable.un_select_icon;
	/**
	 * 重新设置小点的图片
	 *
	 * @param round_select 选中图片
	 *
	 *@param  round_unselect 未选中图片
	 *
	 *
	 * */
	public void setImageResourse( int round_select, int round_unselect) {
		
		this.round_select = round_select;
		this.round_unselect = round_unselect;
	}

	public ImageCountView(Context context) {
		this(context, null);
		// TODO Auto-generated constructor stub
	}

	public ImageCountView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}
	private void init(){
		this.setGravity(Gravity.CENTER_VERTICAL);
		this.setOrientation(LinearLayout.HORIZONTAL);

	}
	/**
	 * 设置小点数量
	 *
	 * @param  count
	 * */
	public void setCountNum(int count){
		if (images != null) {
			for (int i = 0; i < images.length; i++) {
				this.removeView(images[i]);
			}
		}
		images = new ImageView[count];
		for (int i = 0; i < count; i++) {
			images[i] = new ImageView(this.getContext());
			images[i].setImageResource(round_unselect);
			images[i].setPadding(8, 0, 8, 0);
			addView(images[i]);
		}
	}
	/**
	* 选中的位置
	*@param   order 位置
	*
	* */
	public void setSelectOrder(int order){
		if (order >= images.length) {
			return;
		}
		int i = 0;
		for(ImageView imageView : images){
			if (i == order) {
				imageView.setImageResource(round_select);
			}else {
				imageView.setImageResource(round_unselect);
			}
			i++;
		}
		
//		for (int j = 0; j < images.length; j++) {
//			if (j == order) {
//				images[j].setBackgroundResource(R.drawable.im_imagecount_select);
//			}else{
//				images[j].setBackgroundResource(R.drawable.im_imagecount_default);
//			}
//		}
	}

}
